package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PositionData;
import com.ruoyi.system.service.IPositionDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位标准Controller
 *
 * @author ruoyi
 * @date 2025-10-30
 */
@Api("测试")
@RestController
@RequestMapping("/system/data")
public class PositionDataController extends BaseController
{
    @Autowired
    private IPositionDataService positionDataService;

    /**
     * 查询岗位标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(PositionData positionData)
    {
        startPage();
        List<PositionData> list = positionDataService.selectPositionDataList(positionData);
        return getDataTable(list);
    }

    /**
     * 导出岗位标准列表
     */
    @PreAuthorize("@ss.hasPermi('system:data:export')")
    @Log(title = "岗位标准", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PositionData positionData)
    {
        List<PositionData> list = positionDataService.selectPositionDataList(positionData);
        ExcelUtil<PositionData> util = new ExcelUtil<PositionData>(PositionData.class);
        util.exportExcel(response, list, "岗位标准数据");
    }

    /**
     * 获取岗位标准详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/{standardPosition}")
    public AjaxResult getInfo(@PathVariable("standardPosition") String standardPosition)
    {
        return success(positionDataService.selectPositionDataByStandardPosition(standardPosition));
    }

    /**
     * 新增岗位标准
     */
    @PreAuthorize("@ss.hasPermi('system:data:add')")
    @Log(title = "岗位标准", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PositionData positionData)
    {
        return toAjax(positionDataService.insertPositionData(positionData));
    }

    /**
     * 修改岗位标准
     */
    @PreAuthorize("@ss.hasPermi('system:data:edit')")
    @Log(title = "岗位标准", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PositionData positionData)
    {
        return toAjax(positionDataService.updatePositionData(positionData));
    }

    /**
     * 删除岗位标准
     */
    @PreAuthorize("@ss.hasPermi('system:data:remove')")
    @Log(title = "岗位标准", businessType = BusinessType.DELETE)
	@DeleteMapping("/{standardPositions}")
    public AjaxResult remove(@PathVariable String[] standardPositions)
    {
        return toAjax(positionDataService.deletePositionDataByStandardPositions(standardPositions));
    }

    /**
     * 获取岗位标准的上升途径图
     */
    @ApiOperation("获取上升途径")
    @PreAuthorize("@ss.hasPermi('system:data:query')")
    @GetMapping(value = "/promotionPath/{standardPositionCode}")
    public AjaxResult getPromotionPath(@PathVariable("standardPositionCode") String standardPositionCode)
    {
        List<String> promotionPaths = positionDataService.selectPromotionPathsByStandardPositionCode(standardPositionCode);
        return success(promotionPaths);
    }
}
